package com.wolfalpha.utron.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wolfalpha.utron.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义的对话框
 *
 * @author
 */
public class LevelAlertDialog {
    private Context context;
    private android.app.AlertDialog ad;
    private TextView titleView;
    private RelativeLayout messageView;
    private TextView sure;
    private TextView cancel;
    private CheckBox cb0;       //普通合伙人
    private CheckBox cb1;       //优秀合伙人
    private CheckBox cb8;       //认证合伙人

    private LayoutInflater inflater;

    public LevelAlertDialog(Context context) {
        // TODO Auto-generated constructor stub
        this.context = context;
        inflater = LayoutInflater.from(context);
        ad = new android.app.AlertDialog.Builder(context).create();
        ad.show();
        //关键在下面的两行,使用window.setContentView,替换整个对话框窗口的布局
        Window window = ad.getWindow();
        window.setContentView(R.layout.dialog_level);
        titleView = (TextView) window.findViewById(R.id.tv_dialog_base_title);
        messageView = (RelativeLayout) window.findViewById(R.id.rl_dialog_base_message);
        sure = (TextView) window.findViewById(R.id.tv_dialog_base_sure);
        cancel = (TextView) window.findViewById(R.id.tv_dialog_base_cancel);

        cb0 = (CheckBox) window.findViewById(R.id.cb_level_dialog_0);
        cb1 = (CheckBox) window.findViewById(R.id.cb_level_dialog_1);
        cb8 = (CheckBox) window.findViewById(R.id.cb_level_dialog_8);

    }

    /**
     * 设置标题
     *
     * @param title
     */
    public void setTitle(String title) {
        titleView.setText(title);
    }


    /**
     * 设置按钮
     *
     * @param text
     * @param listener
     */
    public void setPositiveButton(String text, final View.OnClickListener listener) {
        sure.setText(text);
        sure.setOnClickListener(listener);
    }

    /**
     * 获取最后选择的结果
     *
     * @return
     */
    public List<Integer> getResult() {
        List<Integer> ins = new ArrayList<Integer>();
        if (cb0.isChecked()) ins.add(0);
        if (cb1.isChecked()) ins.add(1);
        if (cb8.isChecked()) ins.add(8);
        return ins;
    }

    /**
     * 设置按钮
     *
     * @param text
     * @param listener
     */
    public void setNegativeButton(String text, final View.OnClickListener listener) {
        cancel.setText(text);
        cancel.setOnClickListener(listener);
    }

    /**
     * 关闭对话框
     */
    public void dismiss() {
        ad.dismiss();
    }

}